package com.zhiling.www.controller;

import com.zhiling.www.entity.EntrustOrder;
import com.zhiling.www.entity.Result;
import com.zhiling.www.service.EntrustOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/stocktrading")
public class StockTradingController {

    @Autowired
    private EntrustOrderService entrustOrderService;

    //买入股票，添加委托订单
    @PostMapping("/buystock")
    public Result buyStock(@RequestBody EntrustOrder entrustOrder,HttpServletRequest request){
        String token = request.getHeader("token");
        return entrustOrderService.addEntrustOrder(entrustOrder,token);
    }

    //卖出股票，添加委托订单
    @PostMapping("/sellstock")
    public Result sellStock(@RequestBody EntrustOrder entrustOrder,HttpServletRequest request){
        String token = request.getHeader("token");
        return entrustOrderService.addSellEntrustOrder(entrustOrder,token);
    }

    //分页加载委托订单
    @GetMapping("/orderlist")
    public Result orderList(int page, int pageSize,int status, HttpServletRequest request){
        String token = request.getHeader("token");
        return entrustOrderService.orderList(page,pageSize,status,token);
    }

    //撤单
    @GetMapping("/cancelorder")
    public Result cancelOrder(int oid){
        return entrustOrderService.cancelOrder(oid);
    }
}
